<?php
function view_transaksi(){
	view_header_top();
	$id = $_SESSION['logged']['id'];
	$user = getUser($_SESSION['logged']['id']);
	//----------------------------------------------------------------
	$title = "Realita - ".$user['nama'];
	$content = "Realita ".$user['nama'];
	$url = PROFIL_URL."a/".$user['idFB'];
	$image = IMAGE_URL."300x240.gif";	//profpic orangnya / tokonya
	$desc = "Profil orangnya : ".$user['bio'];
	$auth = "RealiTA";
	$qwords = "profil, marketplace, umkm".$user['nama'];
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
	view_header_bottom();
?>
<!-- Content -->
    <!--ul class="breadcrumbs">
	  <li><a href="#">Depan</a></li>
	  <li><a href="#">Marketplace</a></li>
	  <li><a href="#">Toko bagus</a></li>
	  <li class="current"><a href="#">Barang Bagus</a></li>
	</ul-->
	<div class="row">    
		<!-- Main Content Section -->
		<!-- This has been source ordered to come first in the markup (and on small devices) but to be to the right of the nav on larger screens -->
		<div class="large-9 push-3 columns">		  
		  <h3><?php echo $user['nama']; ?></h3>
		  <hr />
		  <?php
		  $belipro = getTransBeli($user['idPengguna']);
		  $belihist = getHistBeli($user['idPengguna']);
		  ?>
		  <h4>BELI</h4>
		  <h5><a href="javascript:bkttp('pro_beli');">Transaksi Proses Beli (<?php echo count($belipro); ?>)</a></h5>
		  <div id="pro_beli" style="display:none">
			  <?php
			  if (count($belipro)<1){
				  echo "<h6>Tidak ada transaksi</h6>";
			  }else{
				  foreach ($belipro as $trans){
					 echo	"<div style=\"margin-bottom:10px\">
								".$trans['no-invoice']." (".convDate($trans['tanggal']).") : Total ".int_to_rp($trans['total-pesanan']-$trans['diskon'])." -Status : ".statTrans($trans['status'])." <a href=\"javascript:bkttp('det_".$trans['idTransaksi']."');\">[detail]</a> ";
								if ($trans['status']==1) echo "<a href=\"".TRANSAKSI_URL."bayar/".$trans['no-invoice']."/".$user['idFB']."/".$trans['idTransaksi']."/\">[konfirmasi bayar]</a> [batal]<br />";
							echo "<div id=\"det_".$trans['idTransaksi']."\" style=\"display:none;margin:5px 0 5px 0\">";
								echo "kepada ".$trans['nama_penerima']." di ".$trans['kota'].", ".$trans['lengkap']."<br />";
								
								echo "nama_barang (qty) dari nama_penjual, Rp. sekian";
							echo "</div>";
					 echo	"</div>";
				  }
			  }
			  ?>
		  </div>
		  <h5><a href="javascript:bkttp('hist_beli');">Riwayat Transaksi Beli (<?php echo count($belihist); ?>)</a></h5>
          <div id="hist_beli" style="display:none">
			  <?php
			  if (count($belihist)<1){
				  echo "<h6>Tidak ada transaksi</h6>";
			  }else{
				  foreach ($belihist as $trans){
					 echo	"<div style=\"margin-bottom:10px\">
								".$trans['no-invoice']." (".convDate($trans['tanggal']).") : Total ".int_to_rp($trans['total-pesanan']-$trans['diskon'])." <a href=\"javascript:bkttp('det_".$trans['idTransaksi']."');\">[detail]</a><br />";
							echo "<div id=\"det_".$trans['idTransaksi']."\" style=\"display:none\">ada isi</div>";
					 echo	"</div>";
				  }
			  }
			  ?>
		  </div>
		  <?php
			if ($user['isToko']){
				$jualpro = getTransJual($user['idPengguna']);
				$jualhist = getHistJual($user['idPengguna']);
		  ?>
		  <h4>JUAL</h4>
		  <h5><a href="javascript:bkttp('pro_jual');">Transaksi Proses Jual (<?php echo count($jualpro); ?>)</a></h5>
		  <div id="pro_jual" style="display:none">
			  <?php
			  if (count($jualpro)<1){
				  echo "<h6>Tidak ada transaksi</h6>";
			  }else{
				  foreach ($jualpro as $trans){
					 echo	"<div style=\"margin-bottom:10px\">
								".$trans['no-invoice']." (".convDate($trans['tanggal']).") : ".$trans['nama']." (".$trans['kuantitas'].") -Status : ".statPesanan($trans['status'])." <a href=\"javascript:bkttp('det_".$trans['idPesanan']."');\">[detail]</a> ";
								if ($trans['status']==2) echo "<a href=\"".TRANSAKSI_URL."kirim/".$trans['idPesanan']."/".$user['idFB']."/".$trans['idTransaksi']."/\">[konfirmasi kirim]</a><br />";
							echo "<div id=\"det_".$trans['idPesanan']."\" style=\"display:none\">ada isi</div>";
					 echo	"</div>";
				  }
			  }
			  ?>
		  </div>
          <h5><a href="javascript:bkttp('hist_jual');">Riwayat Transaksi Jual (<?php echo count($jualhist); ?>)</a></h5>
          <div id="hist_jual" style="display:none">
			 <?php
			  if (count($jualhist)<1){
				  echo "<h6>Tidak ada transaksi</h6>";
			  }else{
				  foreach ($jualhist as $trans){
					 echo	"<div style=\"margin-bottom:10px\">
								".$trans['no-invoice']." (".convDate($trans['tanggal']).") : ".$trans['nama']." (".$trans['kuantitas'].") -Status : ".statPesanan($trans['status'])." <a href=\"javascript:bkttp('det_".$trans['idPesanan']."');\">[detail]</a> ";
							echo "<div id=\"det_".$trans['idPesanan']."\" style=\"display:none\">ada isi</div>";
					 echo	"</div>";
				  }
			  }
			  ?>  
		  </div>
		  <?php
	  }
		  ?>
		</div>
		<!-- Nav Sidebar -->
		<!-- This is source ordered to be pulled to the left on larger screens -->
		<?php view_tab($user); ?>
	  </div>
    <!-- End Content -->
<?php
	view_footer();
}

function view_keranjang(){
	view_header_top();
	$id = $_SESSION['logged']['id'];
	$user = getUser($_SESSION['logged']['id']);
	//----------------------------------------------------------------
	$title = "Realita - ".$user['nama'];
	$content = "Realita ".$user['nama'];
	$url = PROFIL_URL."a/".$user['idFB'];
	$image = IMAGE_URL."300x240.gif";	//profpic orangnya / tokonya
	$desc = "Profil orangnya : ".$user['bio'];
	$auth = "RealiTA";
	$qwords = "profil, marketplace, umkm".$user['nama'];
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
	view_header_bottom();
?>
<!-- Content -->
    <!--ul class="breadcrumbs">
	  <li><a href="#">Depan</a></li>
	  <li><a href="#">Marketplace</a></li>
	  <li><a href="#">Toko bagus</a></li>
	  <li class="current"><a href="#">Barang Bagus</a></li>
	</ul-->
	<div class="row">    
		<!-- Main Content Section -->
		<!-- This has been source ordered to come first in the markup (and on small devices) but to be to the right of the nav on larger screens -->
		<div class="large-9 push-3 columns">		  
		  <h3><?php echo $_SESSION['logged']['name']; ?></h3>
		  <hr />
		  <h4>Keranjang</h4>
		  <?php
		  if (isset($_SESSION['status-keranjang'])) {
				echo "<div class='alert-box success'>".$_SESSION['status-keranjang']."<a href='#' class='close'>&times;</a></div>";
				unset($_SESSION['status-keranjang']);
		}?>
          <div class="row">
           <?php
		   if (isset($_SESSION['keranjang'])){
			   if (count($_SESSION['keranjang'])>0){
				echo "<div class='keranjang'><table class='tabel-keranjang'><thead>";
				echo '<tr class="judul-keranjang"><th>Produk</th><th>Harga</th><th>Qty</th><th>Aksi</th><th colspan="2">Keterangan</th><th>Nominal</th></tr></thead>';
				$total = 0;
				echo '<tbody>';
				foreach ($_SESSION['keranjang'] as $key=>$keranjang) {
					echo "<tr>";
					$barang = getBarang($keranjang['id']);
					echo "<td class='produk'><a href=\"".BARANG_URL."a/".$barang['idBarang']."/".$barang['nama']."\">".$barang['nama']."</a></td>";
					echo '<td class="nominal">'.int_to_rp($barang['harga']).'</td>';
					echo "<td><form action=\"".KERANJANG_URL."ubah\" method=\"post\">";	//tambah barang
						echo "<input type=\"hidden\" name=\"index\" value=\"".$key."\" />";
						echo "<input id='keranjang-input' class='small-2 columns' type=\"text\" name=\"kuantitas\" value=\"".$keranjang['kuantitas']."\" />";
						echo "<input class='input-tombol' type=\"submit\" name=\"update\" value=\"Perbaharui\" /></form></td>";
					echo "<td><form action=\"".KERANJANG_URL."hapus\" method=\"post\">";	//hapus barang
						echo "<input type=\"hidden\" name=\"index\" value=\"".$key."\" />";
						echo "<input class='input-tombol' type=\"submit\" name=\"hapus\" value=\"Hapus\" /></form></td>";
					echo '<td colspan="2" class="nominal">'.$ket = $barang['preorder']==1 ? 'pre-order' : '-'.'</td>';
					$sub = (int)$keranjang['kuantitas']*(int)$barang['harga'];
					$total += $sub;
					echo '<td class="nominal">'.int_to_rp($sub).'</td>';
					echo "</tr>";
				}
				echo '<tr><td colspan="6"><strong>TOTAL</strong></td><td>'.int_to_rp($total).'</td></tr>';
				echo '<tr><td colspan="6"></td><td><a href="'.HOME_URL.'transaksi/co"><strong>[CHECKOUT]</strong></a></td></tr>';
				echo "</tbody></table></div>";
				}else{
					echo "<div class=\"large-9 columns\">Keranjang kosong</div>";
				}
			}else{
					echo "<div class=\"large-9 columns\"><h5>TIDAK ADA BELANJAAN</h5></div>";
			}
           ?>
          </div>
          <hr />
          <div class="row">
			
		  </div>
		</div>
		<!-- Nav Sidebar -->
		<!-- This is source ordered to be pulled to the left on larger screens -->
		<?php view_tab($user); ?>
	  </div>
    <!-- End Content -->
<?php
	view_footer();
}
?>
